package com.heima.user;

import com.alibaba.fastjson.JSON;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

@SpringBootTest
public class YongyouAiDemo {

    @Test
    public void idCardCheck(){

    }

    private Boolean idCardCheck(String idNumber,String username){
        try {
            Map params = new HashMap();
            params.put("idNumber", idNumber);
            params.put("userName", username);
            Map map = executePostReq("72a539be0ece4c75bf0512a2a26c54ad", "https://api.yonyoucloud.com/apis/dst/matchIdentity/matchIdentity", params);
            return (Boolean) map.get("success");
        }catch (Exception e){
            e.printStackTrace();
            System.out.println("调用接口失败");
            return  false;
        }



    }

    private Map executePostReq(String apicode,String url , Map params){
        RestTemplate restTemplate = new RestTemplate();

        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.set("apicode",apicode);
        httpHeaders.setContentType(MediaType.APPLICATION_JSON);

        HttpEntity<String> httpEntity = new HttpEntity<>(JSON.toJSONString(params),httpHeaders);

        ResponseEntity<String> responseEntity = restTemplate.postForEntity(url,httpEntity,String.class);

        String body = responseEntity.getBody();
        return JSON.parseObject(body,Map.class);

    }

}
